package logic;

import java.util.ArrayList;

import model.PredictionEnergyProfile;
import model.ProbabilityEnergyProfile;
import model.ProbabilityUsagetype;
import model.SimpleEnergyProfile;

public class DataMatcher {

	
	public ProbabilityEnergyProfile createProbabilityMatcher(ArrayList<PredictionEnergyProfile> predlist, SimpleEnergyProfile simple) {
		int size = predlist.size();
		ProbabilityEnergyProfile prob = new ProbabilityEnergyProfile(size,simple.getId());
		for (int i=0;i<size;i++) {
			/*ProbabilityUsagetype probusage = new ProbabilityUsagetype(predlist.get(i).getUsageType(),
					predlist.get(i).getProbability(simple),
					predlist.get(i).getZ(simple));*/
			ProbabilityUsagetype probusage = predlist.get(i).getProbabilityUsagetype(simple);
			prob.addProbability(probusage);
			prob.sort();
		}		
		return prob;	
	}
	
	public ArrayList<ProbabilityEnergyProfile> createProbabilityMatcher(ArrayList<PredictionEnergyProfile> predlist, ArrayList<SimpleEnergyProfile> simplelist) {
		ArrayList<ProbabilityEnergyProfile> list = new ArrayList<ProbabilityEnergyProfile>();
		
		for(SimpleEnergyProfile simple : simplelist) {
			ProbabilityEnergyProfile prob = createProbabilityMatcher(predlist,simple);
			list.add(prob);
		}
		return list;	
		
	}
	
	public ProbabilityEnergyProfile createProbabilityMatcherEnergyIntensity(SimpleEnergyProfile simple) {
		ProbabilityEnergyProfile prob = new ProbabilityEnergyProfile(DataInitializer.USAGETYPE_COMMERCIAL.length,simple.getId());
		for (int i=0;i<DataInitializer.USAGETYPE_COMMERCIAL.length;i++) {
			ProbabilityUsagetype probusage = new ProbabilityUsagetype();
			probusage.setUsageType(DataInitializer.USAGETYPE_COMMERCIAL[i]);
			probusage.setZ(Math.abs(simple.getAnnualEnergy()/simple.getAreasqft()
					-DataInitializer.ELECTRICITY_INTENSITY_COMMERCIAL[i]));
			probusage.setProbability(1.0 - probusage.getZ()
					/DataInitializer.ELECTRICITY_INTENSITY_COMMERCIAL[i]);
			prob.addProbability(probusage);
			prob.sort();
		}
		return prob;	
	}
	
	public ArrayList<ProbabilityEnergyProfile> createProbabilityMatcherEnergyIntensity(ArrayList<SimpleEnergyProfile> simplelist) {
		ArrayList<ProbabilityEnergyProfile> list = new ArrayList<ProbabilityEnergyProfile>();
		for(SimpleEnergyProfile simple : simplelist) {
			ProbabilityEnergyProfile prob = createProbabilityMatcherEnergyIntensity(simple);
			list.add(prob);
		}
		return list;
	}
	
	
/*	
	public EnergyProfile matchProfile(SimpleEnergyProfile sep, ArrayList<EnergyProfile> datalist) {
		EnergyProfile retval = null;
		int currmatch = -1;
		int nextmatch = -1;
		for (EnergyProfile obj : datalist){
			nextmatch =  profileDifference(sep,obj);
			if (currmatch < 0 || nextmatch<currmatch ) {
				currmatch = nextmatch;
				retval = obj;
			}
		}
		return retval;
	}
	
	public ArrayList<EnergyProfile> matchProfileList(ArrayList<SimpleEnergyProfile> seplist, ArrayList<EnergyProfile> datalist) {
		ArrayList<EnergyProfile> matchlist = new ArrayList<EnergyProfile>();
		for (SimpleEnergyProfile obj : seplist){
			matchlist.add(matchProfile(obj,datalist));
		}
		return matchlist;
	}
	
	public int profileDifference(SimpleEnergyProfile sep, EnergyProfile ep) {
		return 0;
	}*/
}
